Chinju Gami (鎮守神)
Chinju gami is a (Shinto) god enshrined to guard a particular building or a certain area of land. It is often considered to be the same as ujigami (a guardian god or spirit of a particular place in the Shinto religion) or ubusunagami (guardian deity of one's birthplace). A shrine for chinju gami is called a chinju-sha shrine (Shinto shrine on Buddhist temple grounds dedicated to the tutelary deity of the area).
Summary
The origin of chinju gami is believed to be Garanjin (tutelary deities of temple compounds) of China. Japanese temples started to enshrine gods of heaven and earth in order to protect themselves as Buddhism spread and syncretism of Shinto and Buddhism developed. Then, chinju gami started to be enshrined in structures other than temples or certain areas of land.
It is often believed now that chinju gami is a god that lives in a local area (also known as jinushi gami); however, it was originally a god that was enshrined in order to suppress the jinushi gami and compel its obedience. What this means is that, people called and enshrined a god that had a stronger mysterious power than the jinushi gami so that, when people built a structure on a particular land, spirits in that land would not curse the people or the structure. Then, the jinushi gami was expected to submissively obey the chinju gami and to guard and support its activities (jinushi gami however sometimes resisted chinju gami and caused a curse).
As time passed, however, the original meaning of chinju gami was forgotten, chinju gami and jinushi gami were confused with each other, and they as a result were syncretized. Chinju gami then were enshrined at places such as temples, residences, shoen (manor in medieval Japan), castles, and villages.
One of the possible reasons why chinju gami were started to be enshrined in villages is that, during the course of conflict between a certain village and gozoku (a local ruling family) that controlled its surrounding area, the village enshrined chinju gami in order to counter the mysterious power of ujigami enshrined by gozoku as its family god.